//
//  XRCommonBaseViewController.m
//  LiveIMTool
//
//  Created by NeiQuan on 16/10/26.
//  Copyright © 2016年 AlexiChen. All rights reserved.
//

#import "XRCommonBaseViewController.h"

@interface XRCommonBaseViewController ()

@end

@implementation XRCommonBaseViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = kAppBakgroundColor;
    [self configContainer];
    [self addOwnViews];
    [self configOwnViews];
    [self addNavbarView];
    [self bindViewModel];
}
#pragma mark --addOwnViews
- (void)addOwnViews
{  // 此处添加界面中的控件
    
}
#pragma mark --configOwnViews
- (void)configOwnViews
{ // 此处配置界面中的控件的值
    
}

-(void)addNavbarView
{//添加导航栏设置
    
    
}

-(void)bindViewModel
{//RAC绑定事件
    
    
}
#pragma mark --configContainer
- (void)configContainer
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.automaticallyAdjustsScrollViewInsets=NO;
    self.navigationController.navigationBar.translucent = NO;//透明度
    self.tabBarController.tabBar.translucent = NO;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
-(void)configGestutes
{
//    NSArray *gestureArray = self.navigationController.view.gestureRecognizers;
//    //当是侧滑手势的时候设置scrollview需要此手势失效才生效即可
//    for (UIGestureRecognizer *gesture in gestureArray) {
//        if ([gesture isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
//            [self.scrollView.panGestureRecognizer requireGestureRecognizerToFail:gesture];
//        }
//    }
//    
}
#pragma mark 导航栏
//建议这个项目写在addNavbarView方法下面
- (void)configNavigationBarWithLeftButtonTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle{
    if (leftTitle) {
        UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        [leftBtn setTitle:leftTitle forState:UIControlStateNormal];
        [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        leftBtn.titleLabel.font = [UIFont Y_systemFontOfSize:14];
        [leftBtn addTarget:self action:@selector(navigationBarLeftButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    }
    if (rightTitle) {
        UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        [rightBtn setTitle:rightTitle forState:UIControlStateNormal];
        rightBtn.titleLabel.font =[UIFont Y_systemFontOfSize:14];
        [rightBtn addTarget:self action:@selector(navigationBarRightButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    }
}
- (void)configNavigationBarLeftTitle:(NSString *)leftTitle
{
    if (leftTitle) {
        UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        [leftBtn setTitle:leftTitle forState:UIControlStateNormal];
        [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        leftBtn.titleLabel.font = [UIFont Y_systemFontOfSize:14];
        [leftBtn addTarget:self action:@selector(navigationBarLeftButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    }
    
}
- (void)configNavigationBarLeftImage:(NSString *)leftImageString
{
    if (leftImageString) {
        UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        [leftBtn setImage:[UIImage imageNamed:leftImageString] forState:UIControlStateNormal];
        [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        leftBtn.titleLabel.font = [UIFont Y_systemFontOfSize:14];
        [leftBtn addTarget:self action:@selector(navigationBarLeftButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    }
}
- (void)configNavigationBarRightTitle:(NSString *)rightTitle
{
    if (rightTitle) {
        UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        [rightBtn setTitle:rightTitle forState:UIControlStateNormal];
        rightBtn.titleLabel.font =[UIFont Y_systemFontOfSize:14];
        [rightBtn addTarget:self action:@selector(navigationBarRightButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    }
}
- (void)configNavigationBarRightImage:(NSString *)rightImageString
{
    if (rightImageString) {
        UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
        [rightBtn setImage:[UIImage imageNamed:rightImageString] forState:UIControlStateNormal];
        rightBtn.titleLabel.font =[UIFont Y_systemFontOfSize:14];
        [rightBtn addTarget:self action:@selector(navigationBarRightButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    }
}
//left事件处理
- (void)navigationBarLeftButtonTapped:(UIButton *)sender
{
    
}
//right事件处理
- (void)navigationBarRightButtonTapped:(UIButton *)sender
{
    
    
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return [self shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//解决有水平方向滚动的ScrollView时边缘返回手势失效的问题
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}


@end
